//公共全局组件封装
/**
 * @description 消息提示框
 * @param { Object } options 参数和 wx.showToast 参数保持一致
 */
export const toast = ({ title = '数据加载中...', icon = 'none', duration = 2000, mask = true } = {}) => {
  // 如果用户传入了对象作为参数
  // 在形参位置通过解构的方式获取用户传入的参数，同时设置默认值

  wx.showToast({
    title,
    icon,
    duration,
    mask
  })
}

export const confirmModel = (options = {} as any) => {
  return new Promise((resolve) => {
    const defaultOpt = {
      title: "提示",
      content: "您确定执行改操作吗？",
      confirmColor: "#f3514f"
    }
    //合并参数
    const opts = Object.assign({}, defaultOpt, options)
    wx.showModal({
      //将合并的参数放到这
      ...opts,
      complete(res: { confirm: Boolean, cancel: Boolean, content: String }) {
        const data=res.content
        res.confirm && resolve({
          "isConfirm": true,
          "content":data
        })
        res.cancel && resolve({
          "isConfirm": false,
          "content":data
        })
      }
    })
  })
}

